function myFlat(arr, deps = Infinity) {
  let res = []
  for (let i = 0; i < arr.length; i++) {
    if (Array.isArray(arr[i]) && deps > 0) {
      res = [...res, ...myFlat(arr[i], deps - 1)]
    } else {
      res.push(arr[i])
    }
  }
  return res
}
let a = myFlat([1, 2, 3, [3, [5, 6, 7], 5], 4, 5])
console.log(a);